package io.gitee.bluemiaomiao.dataanalyzebackend.controller;

import com.alibaba.fastjson.JSONObject;
import io.gitee.bluemiaomiao.dataanalyzebackend.domian.Ruser;
import io.gitee.bluemiaomiao.dataanalyzebackend.domian.imgtable.VipTimeAgeSex;
import io.gitee.bluemiaomiao.dataanalyzebackend.domian.imgtable.number;
import io.gitee.bluemiaomiao.dataanalyzebackend.repos.ImgtableMapper;
import io.gitee.bluemiaomiao.dataanalyzebackend.util.ResultCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * @author Administrator
 * @description 会员分析请求
 */
@RestController
@RequestMapping(value = "/first")
public class VipAnalysisController {

  @Autowired private ImgtableMapper imgtableMapper;

  @ResponseBody
  @RequestMapping(value = "imgtable/cxVipTime", method = RequestMethod.POST)
  public String age(VipTimeAgeSex vipTimeAgeSex) {
    List<number> a = imgtableMapper.cxVipTime(vipTimeAgeSex);
    String json = JSONObject.toJSONString(a);
    return json;
  }

  @ResponseBody
  @RequestMapping(value = "imgtable/sex", method = RequestMethod.POST)
  public String sex(VipTimeAgeSex vipTimeAgeSex) {

    List<number> a = imgtableMapper.cxTimeAgeSex(vipTimeAgeSex);
    String json = JSONObject.toJSONString(a);
    return json;
  }

  @ResponseBody
  @RequestMapping(value = "imgtable/Shoptime", method = RequestMethod.POST)
  public String Shoptime(
      @RequestParam("befor") String befor,
      @RequestParam("lafter") String lafter,
      @RequestParam("shop_name") String shop_name,
      @RequestParam("commodity_qrline ") String commodity_qrline) {

    List<number> a = imgtableMapper.cxShoptime(shop_name, befor, lafter, commodity_qrline);
    String json = JSONObject.toJSONString(a);
    return json;
  }

  @ResponseBody
  @RequestMapping(value = "imgtable/sex_mon", method = RequestMethod.POST)
  public String sex_time_1(
      @RequestParam("befor") String befor,
      @RequestParam("lafter") String lafter,
      @RequestParam("shop_name") String shop_name,
      String VeLineId,
      @RequestParam("commodity_qrline") String commodity_qrline)
      throws ParseException {

    int Id = Integer.parseInt(VeLineId);
    List<number> a = imgtableMapper.cxtime_1(Id, shop_name, befor, lafter, commodity_qrline);
    String json = JSONObject.toJSONString(a);
    return json;
  }

  @ResponseBody
  @RequestMapping(value = "shop/name", method = RequestMethod.POST)
  public String ShopName() {
    List<String> a = imgtableMapper.cxshopname();
    a.add(0, "全部店铺");
    String json = JSONObject.toJSONString(a);
    return json;
  }

  @GetMapping(value = "/GetUserInfo")
  public ResultCodeUtil GetUserInfo() {
    Ruser ruser = (Ruser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    System.out.println(ruser.getUsername());
    return ResultCodeUtil.success(ruser, "success");
  }
}
